var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        language: "",
        amount_id: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        popularVideo: [],
        heightauto: "auto",
        widthauto: "auto",
        showVideo: {},
        myvideo: "",
        show: !1,
        screeheight: 0,
        minStyle: !0,
        firstcontent: !1,
        cleartime: null,
        realIndex: 0,
        kFootshow: !0,
        is_plugins: 0,
        timer: null,
        advertisingt_type: 0,
        commentsShow: !1,
        readReawrdList: {},
        rewardShow: !1,
        attentionRewaedData: {},
        attentionRewaedShow: !1,
        reward_button: {}
    },
    onLoad: function(t) {
        this.data.myvideo = wx.createVideoContext("myvideo"), this.getinformation(), t.advertisingt_type && (this.data.advertisingt_type = t.advertisingt_type), 
        t.vid && this.setData({
            amount_id: t.vid
        }), t.mid && (a._setMid(t.mid), this.sendForwardReward()), t.page && this.setData({
            page: Number(t.page) ? Number(t.page) : 0
        }), !t.page && t.vid || this.getData();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    handAttentionRewaed: function(t) {
        this.setData({
            attentionRewaedData: t.detail,
            attentionRewaedShow: !0
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        t && (a = t);
        var e = {}, i = "";
        return this.data.popularVideo[this.data.realIndex] && this.data.popularVideo[this.data.realIndex].cover_picture && (i = this.data.popularVideo[this.data.realIndex].cover_picture), 
        e = {
            title: this.data.showVideo.title ? this.data.showVideo.title : "",
            query: "vid=" + this.data.amount_id + "&page=" + this.page + "&mid=" + a + "&advertisingt_type=" + this.data.advertisingt_type
        }, i && (e.imageUrl = i), console.log(e), e;
    },
    onShareAppMessage: function(t) {
        var a = wx.getStorageSync("yz_uid"), e = "";
        a && (e = a);
        var i = {}, d = "";
        return this.data.popularVideo[this.data.realIndex] && this.data.popularVideo[this.data.realIndex].cover_picture && (d = this.data.popularVideo[this.data.realIndex].cover_picture), 
        i = {
            title: this.data.showVideo.title ? this.data.showVideo.title : "",
            path: "/packageI/newMedia/newMediaAdVideo/newMediaAdVideo?vid=" + this.data.amount_id + "&page=" + this.data.page + "&mid=" + e + "&advertisingt_type=" + this.data.advertisingt_type
        }, d && (i.imageUrl = d), console.log(i), i;
    },
    getData: function() {
        var t, e = this;
        t = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.get-list"), 
        t += "&page=" + this.data.page, t += "&advertisingt_type=" + this.data.advertisingt_type, 
        1 == this.data.advertisingt_type && (t += "&genre=4"), a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    e.data.isLoadMore = !0, e.data.total_page = a.data.list.last_page, e.data.total_page || (e.data.total_page = 0), 
                    e.setData({
                        popularVideo: a.data.list.data,
                        reward_button: a.data.reward_button
                    });
                    var i = a.data.list.data;
                    if (e.data.amount_id) {
                        for (var d = 0; d < a.data.list.data.length; d++) if (a.data.list.data[d].id == e.data.amount_id) return e.setData({
                            showVideo: a.data.list.data[d]
                        }), i.splice(0, d), e.setData({
                            popularVideo: i
                        }), wx.setNavigationBarTitle({
                            title: e.data.showVideo.title
                        }), e.setData({
                            firstcontent: !0
                        }), void e.clickSwiperbtn(0);
                        wx.setNavigationBarTitle({
                            title: e.data.showVideo.title
                        });
                    } else e.setData({
                        showVideo: e.data.popularVideo[0]
                    }), e.clickSwiperbtn(0);
                    e.setData({
                        firstcontent: !0
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getinformation: function() {
        try {
            var t = wx.getSystemInfoSync(), a = t.windowHeight, e = t.windowWidth;
            this.setData({
                heightauto: a + "px",
                widthauto: e + "px"
            }), this.data.screeheight = a;
        } catch (t) {}
    },
    clickSwiperbtn: function(t) {
        var a = 0;
        a = t.currentTarget ? t.currentTarget.dataset.index : t, this.clickSwiper(a);
    },
    clickSwiper: function(a) {
        var e = a;
        if (console.log("zhixing"), this.data.popularVideo[e].show && this.data.amount_id === this.data.popularVideo[e].id) return this.setData(t({
            show: !1
        }, "popularVideo[" + e + "].show", !1)), void this.data.myvideo.pause();
        this.judgmentpic(e), this.setData(t({
            show: !0,
            amount_id: this.data.popularVideo[e].id
        }, "popularVideo[" + e + "].show", !0)), this.data.logID = 0, this.data.myvideo.play(), 
        this.selectComponent("#commentList").getStickComment(), this.addReadReward(), console.log("执行-----------");
    },
    popularVideoChange: function(t) {
        clearTimeout(this.data.cleartime);
        var a = t.detail.current;
        this.data.realIndex = a, this.data.AnswerID = 0, this.data.cumulativeDuration = parseInt(this.data.cumulativeDuration + this.data.currentDuration), 
        this.data.currentDuration = 0, this.judgmentpic_2(a);
    },
    judgmentpic_2: function(t) {
        var a = t, e = this;
        try {
            if (e.data.popularVideo[a] && e.data.popularVideo[a].cover) {
                var i = wx.createSelectorQuery();
                i.select("#pic_" + a).boundingClientRect(), i.exec(function(t) {
                    var i = e.data.screeheight;
                    t[0] && t[0].height ? t[0].height > Math.ceil(i * (7 / 8)) ? (e.setData({
                        minStyle: !1
                    }), e.getvideomessage(a)) : (e.setData({
                        minStyle: !0
                    }), e.getvideomessage(a)) : (e.setData({
                        minStyle: !0
                    }), e.getvideomessage(a));
                });
            } else e.setData({
                minStyle: !0
            }), e.getvideomessage(a);
        } catch (t) {
            e.setData({
                minStyle: !0
            }), e.getvideomessage(a);
        }
    },
    getvideomessage: function(a) {
        var e, i, d = this;
        (a == d.data.popularVideo.length - 2 && d.getMoreData(), this.data.myvideo.pause(), 
        d.setData({
            show: !1,
            showVideo: d.data.popularVideo[a]
        }), 0 === a) ? this.setData((t(e = {}, "popularVideo[" + a + "].show", !1), t(e, "popularVideo[" + (a + 1) + "].show", !1), 
        e)) : (this.setData((t(i = {}, "popularVideo[" + (a - 1) + "].show", !1), t(i, "popularVideo[" + a + "].show", !1), 
        i)), d.data.popularVideo[a + 1] && this.setData(t({}, "popularVideo[" + (a + 1) + "].show", !1)));
        wx.setNavigationBarTitle({
            title: d.data.showVideo.title
        }), wx.setStorageSync("circle_invitation_id", this.data.showVideo.id), this.data.cleartime = setTimeout(function() {
            d.clickSwiper(a);
        }, 300);
    },
    getMoreData: function() {
        var t = this;
        if (t.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var e = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.get-list");
            a._getNetWork({
                url: e,
                data: {
                    page: this.data.page
                },
                success: function(a) {
                    t.data.isLoadMore = !0;
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data.list.data;
                        t.setData({
                            popularVideo: t.data.popularVideo.concat(i)
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    judgmentpic: function(t) {
        var a = t, e = this, i = wx.createSelectorQuery();
        i.select("#pic_" + a).boundingClientRect(), i.exec(function(t) {
            var a = e.data.screeheight;
            t[0].height > Math.ceil(a * (7 / 8)) ? e.setData({
                minStyle: !1
            }) : e.setData({
                minStyle: !0
            });
        });
    },
    endedPlay: function() {
        console.log("播放结束");
    },
    onPlaying: function() {
        console.log("onPlaying=================");
    },
    setCommentShow: function() {
        this.setData({
            commentsShow: !this.data.commentsShow
        });
    },
    setRewardShow: function() {
        this.setData({
            rewardShow: !this.data.rewardShow
        });
    },
    addReadReward: function() {
        var t = this, e = this.data, i = e.amount_id;
        if (!e.readReawrdList[i]) {
            this.data.readReawrdList[i] = i;
            var d = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.advertisingt-info");
            a._getNetWork({
                url: d,
                data: {
                    advertisingt_id: i
                },
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data;
                        t.setData({
                            reward_name: i.reward_name
                        }), i.behavioral && i.behavioral.is_reward && 1 == i.behavioral.is_reward && t.setData({
                            attentionRewaedData: i.behavioral,
                            attentionRewaedShow: !0
                        });
                    }
                }
            });
        }
    },
    sendForwardReward: function() {
        var t = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.forward-reward");
        a._getNetWork({
            url: t,
            data: {
                advertisingt_id: this.data.amount_id
            },
            success: function(t) {
                var e = t.data;
                if (1 != e.result) return a.tips(e.msg);
            }
        });
    },
    handCommentSuccess: function(a) {
        var e, i = a.detail.type, d = this.data.popularVideo[this.data.realIndex].comment_count;
        "add" == i ? d++ : "reduce" == i && d--;
        var o = "popularVideo[" + this.data.realIndex + "].comment_count";
        this.setData((t(e = {}, o, d), t(e, "showVideo.comment_count", d), e));
    },
    setAttentionRewaedShow: function() {
        this.setData({
            attentionRewaedShow: !this.data.attentionRewaedShow
        });
    },
    sendAttention: function(t) {
        var e = this, i = t.currentTarget.dataset.item, d = t.currentTarget.dataset.index, o = i.is_attention, n = "", s = {};
        o ? (n = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.cancel-attention"), 
        s.advertisingt_member = i.member_id) : (n = a.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.attention"), 
        s.advertisingt_id = i.id), a._getNetWork({
            url: n,
            data: s,
            success: function(t) {
                var i = t.data;
                if (1 != i.result) return a.tips(i.msg);
                var n = {};
                n["popularVideo[" + d + "].is_attention"] = !o, 1 == i.data.is_reward && (n.attentionRewaedData = i.data, 
                n.attentionRewaedShow = !0), e.setData(n);
            }
        });
    },
    handFavorites: function(t) {
        var a = t.target.dataset.index, e = t.detail.favorites_count, i = t.detail.is_favorites, d = {};
        d["popularVideo[" + a + "].is_favorites"] = !i, d["popularVideo[" + a + "].favorites_count"] = e, 
        this.setData(d);
    },
    handLike: function(t) {
        var a = t.target.dataset.index, e = t.detail.like_count, i = t.detail.is_like, d = {};
        d["popularVideo[" + a + "].is_like"] = !i, d["popularVideo[" + a + "].like_count"] = e, 
        this.setData(d);
    }
});